﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Model.Domain;
using System.Data.Common;
using IMPlant.Core.Data.Unity;
using System.Data;
using SMTC.Model.Model;

namespace SMTC.Dao.Plant
{
    public class PlantQueryDao : BaseDao
    {
        /// <summary>
        /// 查询plant列表
        /// </summary>
        private const string SQL_SELECT_PLAN = @"SELECT PlantID,
	                                                   PlantName,
	                                                   ModifyPerson,
	                                                   ModifyDateTime,
	                                                   PlantCapacity FROM dbo.SMT_Plant
                                                WHERE PlantName LIKE @PlantName
                                                AND ModifyPerson LIKE @ModifyPerson
                                                AND ModifyDateTime BETWEEN @starTime AND @endTime";
        /// <summary>
        /// 查询plant下的bu列表
        /// </summary>
        private const string SQL_SELECT_PLAN_BUS = @"SELECT BUID,
	                                                       BUName,
	                                                       PlantID,
	                                                       BUCapacity,
	                                                       ModifyPerson,
	                                                       ModifyDateTime FROM dbo.SMT_BU 
                                                    WHERE PlantID = @PlantID";
        /// <summary>
        /// 查询单个plant实体
        /// </summary>
        private const string SQL_SELECT_PLANT_SINGLE = @"SELECT PlantID,
	                                                           PlantName,
	                                                           ModifyPerson,
	                                                           ModifyDateTime,
	                                                           PlantCapacity FROM dbo.SMT_Plant
                                                        WHERE PlantID = @PlantID";
        /// <summary>
        /// 获取工厂list信息
        /// </summary>
        /// <param name="PlantName"></param>
        /// <param name="ModifyPerson"></param>
        /// <param name="starTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<SMT_PlantModel> GetPlantList(string PlantName, string ModifyPerson, DateTime starTime, DateTime endTime)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@PlantName",PlantName)
               ,DBparameterBuild.Build("@ModifyPerson",ModifyPerson)
               ,DBparameterBuild.Build("@starTime",starTime)
               ,DBparameterBuild.Build("@endTime",endTime)
            };

            return DBTemplete.ExcuteGetList<SMT_PlantModel>(CommandType.Text, SQL_SELECT_PLAN, parameters);
        }
        /// <summary>
        /// 获取工厂单个实体
        /// </summary>
        /// <param name="PlantID"></param>
        /// <returns></returns>
        public SMT_PlantModel GetPlantModel(string PlantID)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@PlantID",PlantID)
            };

            return DBTemplete.ExcuteGetObject<SMT_PlantModel>(CommandType.Text, SQL_SELECT_PLANT_SINGLE, parameters);
        }
        /// <summary>
        /// 获取工厂下的所有bu的list
        /// </summary>
        /// <param name="PlantID"></param>
        /// <returns></returns>
        public List<SMT_BUModel> GetPlantsBU(string PlantID)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@PlantID",PlantID)
            };

            return DBTemplete.ExcuteGetList<SMT_BUModel>(CommandType.Text, SQL_SELECT_PLAN_BUS, parameters);
        }
    }
}
